/**
 * 
 */
package servlets;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import metier.Bean;
import metier.CategorieSport;

import org.apache.log4j.Logger;

import persistence.Strategie;
import persistence.DAO.DAO;
import persistence.Factories.DAOFactory;

/**
 * @author hozakan
 *
 */
public class GoToAdministration extends BaseServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -222208639614442818L;
	private static final Logger LOGGER = Logger.getLogger(GoToAdministration.class);

	/* (non-Javadoc)
	 * @see servlets.BaseServlet#specificDoGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	protected void specificDoGet(HttpServletRequest request,
			HttpServletResponse response) {
		List<Bean> beans = Strategie.getInstance().getDAOFactory().getDAO(new CategorieSport()).getBeans();
		List<CategorieSport> list = new ArrayList<CategorieSport>();
		if (beans != null) {
			for (Bean bean : beans) {
				list.add((CategorieSport) bean);
			}
		}
		request.getSession(false).setAttribute("categories", list);
		try {
			if (LOGGER.isDebugEnabled()) {
				LOGGER.debug("avant la redirection");
			}
			request.getRequestDispatcher("/pages/administration.jsp").forward(request, response);
		} catch (ServletException e) {
			LOGGER.error("Impossible de rediriger vers la page d'administration");
		} catch (IOException e) {
			LOGGER.error("La page d'administration n'a pas été trouvée à l'endroit indiqué");
		}
	}

	@Override
	protected void specificDoPost(HttpServletRequest request,
			HttpServletResponse response) {
		//No job to do
	}

}
